package com.evildog.workspace.dependencies.ding.bean;

import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * 钉钉机器人的message bean
 * FeedCard和独立跳转ActionCard类型暂时没加，用不到，想偷懒
 *
 * @link {https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq}
 */
@Data
@Accessors(chain = true)
public class DingRobotMessage implements Serializable {

    private static final long serialVersionUID = -5002386754129005802L;

    @Data
    public static class DingAt implements Serializable{

        private static final long serialVersionUID = 8355714884550471949L;

        private List<String> atMobiles;

        private Boolean isAtAll;
    }

    @Data
    @Builder
    public static class Text implements Serializable{

        private static final long serialVersionUID = -4746712067369369007L;
        public static final String MSG_TYPE = "text";

        private String content;
    }

    @Data
    @Builder
    public static class Link implements Serializable{
        public static final String MSG_TYPE = "link";

        private static final long serialVersionUID = -2305190687937379125L;
        private String text;

        private String title;

        private String picUrl;

        private String messageUrl;
    }

    @Data
    @Builder
    public static class Markdown implements Serializable{
        public static final String MSG_TYPE = "markdown";

        private static final long serialVersionUID = -2305190687937379125L;
        private String text;
        private String title;
    }

    @Data
    @Builder
    public static class ActionCard implements Serializable{
        public static final String MSG_TYPE = "actionCard";
        private static final long serialVersionUID = -2305190687937379125L;

        private String text;
        private String title;
        private String btnOrientation;
        private String singleTitle;
        private String singleURL;
    }

    private String msgtype;

    private DingAt at;

    private Text text;

    private Markdown markdown;

    private Link link;

    private ActionCard actionCard;

    public DingRobotMessage at(boolean atAll, List<String> atMobiles){
        DingAt dingAt = new DingAt();
        if(atAll){
            dingAt.setIsAtAll(true);
        }else{
            dingAt.setAtMobiles(atMobiles);
        }

        this.setAt(dingAt);
        return this;
    }
}
